/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ens.delegation.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.ens.delegation.bo.Service;
import org.ens.delegation.dao.IServiceDao;

/**
 *
 * @author amine
 */
public class ServiceAction extends GenericAction {

    private Service service;
    private List listServicePag;
    private String[] columnsSort = {"", "description"};
    private Map _jsonPaginator;
    private Map jsonResult;
    private Map jsonData;
    private String start;
    private String length;
    private String sort;
    private String sortdir;
    private String echo;
    private String strDescription;
    private IServiceDao serviceDao;

    public ServiceAction() {
    }

    public ServiceAction(IServiceDao serviceDao) {
        this.serviceDao = serviceDao;
    }

    @Override
    public String execute() throws Exception {
        setService(null);
        setActionMessages(null);
        return SUCCESS;
    }

    @Override
    public String searchPaginator() {

        setJsonPaginator(new HashMap<String, Object>());

        setListServicePag(getServiceDao().findByFiltersWithFirstMaxResult(Integer.valueOf(getStart()), Integer.valueOf(getLength()), getColumnsSort()[Integer.valueOf(getSort())], getSortdir(), getStrDescription()));

        getJsonPaginator().put("sEcho", getEcho());

        Integer rowCount = getServiceDao().getRowCountByFilters(getStrDescription());

        getJsonPaginator().put("iTotalRecords", String.valueOf(rowCount));

        if (Integer.valueOf(getLength()).compareTo(rowCount) > 0) {
            getJsonPaginator().put("iTotalDisplayRecords", getLength());
        } else {
            getJsonPaginator().put("iTotalDisplayRecords", String.valueOf(rowCount));
        }

        String[][] aaData = new String[getListServicePag().size()][];
        for (int i = 0; i < getListServicePag().size(); i++) {
            Service se = (Service) getListServicePag().get(i);
            String s[] = new String[3];
            s[0] = "<input type=\"checkbox\" name=" + se.getId()
                    + "></input>";
            s[1] = se.getDescription();
            s[2] = "<a href=\"getServicesMod.go?ids=" + se.getId()
                    + "\"><img src=\"./gfx/icon-edit.png\" alt=\"edit\" /></a>";
            aaData[i] = s;
        }

        getJsonPaginator().put("aaData", aaData);
        return SUCCESS;
    }

    @Override
    public String add() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String edit() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String save() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String saveNew() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String delete() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * @return the _jsonPaginator
     */
    public Map getJsonPaginator() {
        return _jsonPaginator;
    }

    /**
     * @param jsonPaginator the _jsonPaginator to set
     */
    public void setJsonPaginator(Map jsonPaginator) {
        this._jsonPaginator = jsonPaginator;
    }

    /**
     * @return the jsonResult
     */
    public Map getJsonResult() {
        return jsonResult;
    }

    /**
     * @param jsonResult the jsonResult to set
     */
    public void setJsonResult(Map jsonResult) {
        this.jsonResult = jsonResult;
    }

    /**
     * @return the jsonData
     */
    public Map getJsonData() {
        return jsonData;
    }

    /**
     * @param jsonData the jsonData to set
     */
    public void setJsonData(Map jsonData) {
        this.jsonData = jsonData;
    }

    /**
     * @return the start
     */
    public String getStart() {
        return start;
    }

    /**
     * @param start the start to set
     */
    public void setStart(String start) {
        this.start = start;
    }

    /**
     * @return the length
     */
    public String getLength() {
        return length;
    }

    /**
     * @param length the length to set
     */
    public void setLength(String length) {
        this.length = length;
    }

    /**
     * @return the sort
     */
    public String getSort() {
        return sort;
    }

    /**
     * @param sort the sort to set
     */
    public void setSort(String sort) {
        this.sort = sort;
    }

    /**
     * @return the sortdir
     */
    public String getSortdir() {
        return sortdir;
    }

    /**
     * @param sortdir the sortdir to set
     */
    public void setSortdir(String sortdir) {
        this.sortdir = sortdir;
    }

    /**
     * @return the echo
     */
    public String getEcho() {
        return echo;
    }

    /**
     * @param echo the echo to set
     */
    public void setEcho(String echo) {
        this.echo = echo;
    }

    /**
     * @return the columnsSort
     */
    public String[] getColumnsSort() {
        return columnsSort;
    }

    /**
     * @param columnsSort the columnsSort to set
     */
    public void setColumnsSort(String[] columnsSort) {
        this.columnsSort = columnsSort;
    }

    /**
     * @return the service
     */
    public Service getService() {
        return service;
    }

    /**
     * @param service the service to set
     */
    public void setService(Service service) {
        this.service = service;
    }

    /**
     * @return the listServicePag
     */
    public List getListServicePag() {
        return listServicePag;
    }

    /**
     * @param listServicePag the listServicePag to set
     */
    public void setListServicePag(List listServicePag) {
        this.listServicePag = listServicePag;
    }

    /**
     * @return the strDescription
     */
    public String getStrDescription() {
        return strDescription;
    }

    /**
     * @param strDescription the strDescription to set
     */
    public void setStrDescription(String strDescription) {
        this.strDescription = strDescription;
    }

    /**
     * @return the serviceDao
     */
    public IServiceDao getServiceDao() {
        return serviceDao;
    }

    /**
     * @param serviceDao the serviceDao to set
     */
    public void setServiceDao(IServiceDao serviceDao) {
        this.serviceDao = serviceDao;
    }
}
